package cn.web.test;

import cn.web.management.domain.Salary;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

public class createSalary {
    public static void main(String[] args) throws IOException {
        String fileName = "C:\\Users\\涂睿星\\Desktop\\salary.sql";
        File file = new File(fileName);
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, true));
        bufferedWriter.write("insert into salary\nvalues\n");

        String s = "";
        String tempString = "";
        Random random;
        Salary salary;


        int number = 100;
        int year = 10;

        //2010年开始
//        MLD 2021 01 03 00001
        for (int i = 2010; i < 2010+year; i++) {
            for (int j = 1; j <= 12; j++) {
                for (int k = 0; k < number+1; k++) {
                    salary = new Salary();
                    //单号
                    random = new Random();
                    s = "MLD";

                    tempString = "";
                    tempString+=i;
                    if (j<10)
                        tempString+=0;
                    tempString+=j;
                    tempString+=0;
                    tempString+=(random.nextInt(5)+1);
                    s+=tempString;

                    for (int l = 0; l < 5-(k+"").length(); l++) {
                        s+="0";
                    }
                    s+=k;
                    salary.setPayroll(s);

                    //员工号
                    s = "E";
                    for (int l = 0; l < 5-(k+"").length(); l++) {
                        s+="0";
                    }
                    s+=k;
                    salary.setEmployno(s);

                    //支付时间
                    salary.setPayoff_time(tempString);


                    int num = 0;
                    int temp = 0;
                    //基本工资
                    num=random.nextInt(5000)+3000;
                    temp+=num;
                    s = ""+num;
                    salary.setBase_salary(s);

                    //在职天数
                    s = ""+(random.nextInt(15)+15);
                    salary.setWorking_time(s);

                    //奖金
                    num=random.nextInt(2000)+500;
                    temp+=num;
                    s = ""+num;
                    salary.setBonus(s);

                    //职务补贴
                    num=random.nextInt(500)+100;
                    temp+=num;
                    s = "" + num;
                    salary.setSubsidies(s);

                    //加班补贴
                    num=random.nextInt(2000)+500;
                    temp+=num;
                    s = ""+num;
                    salary.setOvertime_salary(s);

                    //迟到请假
                    num=random.nextInt(1000);
                    temp-=num;
                    s = ""+num;
                    salary.setLeave_late(s);

                    //缴税
                    num=random.nextInt(1000)+500;
                    temp-=num;
                    s = ""+num;
                    salary.setTax(s);


                    //工资金额
                    salary.setSalary_number(temp+"");
                    bufferedWriter.write(salary.toString()+",\n");
                }
            }
        }
        bufferedWriter.flush();
        bufferedWriter.close();
        System.out.println("生成成功");
    }
}
